#include <stdio.h>
int main()
{
  int i=0,n,sum=0;
  scanf("%d",&n);
  while(n){
    sum+=n;
    i+=n%3;
    n=n/3;
  }
  i/=3;
  sum+=i;
  printf("%d",sum);
  return 0;
}
